package cases.control 
{
	import com.greensock.easing.Strong;
	import flash.display.Shape;
	import flash.geom.Point;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.Fusion;
	import org.despair2D.ui.puppet.AnimePuppet;
	import org.despair2D.ui.puppet.DisplayObjectContainerPuppet;
	import com.greensock.TweenLite

	
public class MultipleButtonController
{
	
	public function MultipleButtonController( F:Fusion )
	{

		var DOC:DisplayObjectContainerPuppet = F.createDisplayObjectContainerPuppet()
		DOC.addEventListener(ManipulateEvent.PRESS, press)
		
		var shape:Shape = DOC.addChild(new Shape) as Shape
		shape.graphics.beginFill(0xdddd22, 0.9);
		shape.graphics.lineStyle(1, 0);
		shape.graphics.drawCircle( 10, 10, 5);

		//var tp:TextPuppet = this.createTextPuppet('despair', 0, -1)
		//tp.font = 'Courier New'
		
		F.addEventListener(ManipulateEvent.OVER,_dOver);
		F.addEventListener(ManipulateEvent.LEAVE, _dLeave);
		F.addEventListener(ManipulateEvent.KILLED, _killed);
	}
	
	
	
	
	protected function _dOver(e:ManipulateEvent):void
	{
		var F:Fusion = e.target as Fusion
		var m_b:AnimePuppet = F.getPuppetByName('a') as AnimePuppet;
		
		
		if (!m_b)
		{
			m_b = F.createAnimePuppet('colonist_32_32', 0, 'a');
			m_b.move(32, 10)
			m_b.interactive = false;
			m_b.alpha = 0.2
		}
		//m_b.width = 60
		//m_b.height = 60
		m_b.createActionReaction('right_run', null, true, 0.1).play();
		//m_b.move(0, 0);
		TweenLite.to(m_b, 0.5, {x: 70, alpha:1, overwrite:1});
	}
	
	protected function _dLeave(e:ManipulateEvent):void
	{
		var F:Fusion = e.target as Fusion
		var m_b:AnimePuppet = F.getPuppetByName('a') as AnimePuppet;
		
		if (m_b)
		{
			m_b.createActionReaction('left_run',null,true, 0.1, 0, 0.4).play();
			//m_b.move(0, 0);
			TweenLite.to(m_b, 0.6, { x: 32, width:m_b.originWidth, height:m_b.originHeight, alpha:0.2,overwrite:1,ease:Strong.easeOut, onComplete:function():void
			{
				
				m_b.kill()
			}})
		}

	}
	
	private function press(e:ManipulateEvent):void
	{
		trace('press');
	}
	
	private function _killed(e:ManipulateEvent):void
	{
		var F:Fusion = e.target as Fusion
		trace('killed: ' + F.name);
		var m_b:AnimePuppet = F.getPuppetByName('a') as AnimePuppet;
		
		if (m_b)
		{
			TweenLite.killTweensOf(m_b, true);
			m_b=null
		}
	}

}

}